Fix currency input regex + migrate to storybook/test v9#10
Conversation
- Replace permissive regex with two-stage parse: strip non-numeric, then clamp to valid number format (optional leading minus, single decimal point). Prevents malformed input like '1.2.3' or '1-2-3'. - Remove @storybook/test (v8) and @storybook/testing-library, migrate imports to storybook/test (v9 path). Eliminates SB9 compatibility warning. - All 51 interaction tests pass.
|
📝 Storybook Preview: View Storybook This preview will be updated automatically when you push new changes to this PR.
|
- Extract regex literals to module-level constants (biome/useTopLevelRegex) - Fix import ordering in story files (biome/organizeImports) - All 51 tests still passing
WalkthroughThe change tightens controlled currency input parsing with shared regex constants, removes a redundant Storybook test dependency, reorders story imports, and records a patch release changeset. ChangesCurrency input and docs test cleanup
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.changeset/currency-input-fix.md:
- Around line 5-8: Update the changeset for `@lambdacurry/medusa-forms` to cover
only the published currency-input behavior; remove the internal Storybook/test
v9 migration from the release note. In the currency parsing description, refer
to normalization of malformed values, including stripping non-numeric characters
and clamping the format, rather than claiming they are rejected.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9c96cebe-66b5-429a-85ad-2817eb242c7e
📒 Files selected for processing (1)
.changeset/currency-input-fix.md
| Fix currency input regex to reject malformed numbers and migrate to storybook/test v9 | ||
|
|
||
| - Tighten number parsing: strip non-numeric, then clamp to valid format (no more `1.2.3` or `1-2-3`) | ||
| - Migrate `@storybook/test@8` → `storybook/test` (v9), removing compatibility warning |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Keep the changeset scoped to the published package and actual behavior.
@lambdacurry/medusa-forms is the only package in the frontmatter, but the Storybook migration is an internal docs change. Also, ControlledCurrencyInput.tsx:6-48 normalizes/truncates malformed values rather than rejecting them. Keep this release note focused on currency parsing and describe the behavior as normalization.
Suggested wording
-Fix currency input regex to reject malformed numbers and migrate to storybook/test v9
+Normalize malformed currency input to a single numeric value🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.changeset/currency-input-fix.md around lines 5 - 8, Update the changeset
for `@lambdacurry/medusa-forms` to cover only the published currency-input
behavior; remove the internal Storybook/test v9 migration from the release note.
In the currency parsing description, refer to normalization of malformed values,
including stripping non-numeric characters and clamping the format, rather than
claiming they are rejected.
Changes
1. Tighten currency input number parsing
The old regex
/[^0-9.-]+/gwas too permissive — it allowed multiple decimal points (1.2.3) and minus signs anywhere (1-2-3). Replaced with a two-stage parse:/^-?\d*\.?\d*/(optional leading minus, digits, optional single decimal point + digits)2. Migrate
@storybook/test→storybook/test(v9)Storybook 9 merged test utilities into the main
storybookpackage. Removed the old@storybook/test@8.6.14and@storybook/testing-librarypackages, updated imports in story files. Eliminates the SB9 compatibility warning at startup.Test results
Summary by CodeRabbit
Bug Fixes
1.2.3or1-2-3) while keeping typing behavior consistent.Chores